/*
The MIT License (MIT)

Copyright (c) 2013 Mike Dapiran, Brian May, Richard Pospesel, and Bert Wierenga

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software 
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#pragma once
#include <xmmintrin.h>
#include "hhdMathConfig.h"

namespace hhd
{
	class HVector3;
	class HVector4;
	/**
	* \class Hogshead::HMatrix4x4
	* This class represents a 4x4 affine transformation matrix. The internal data is stored column contiguous  
	* interfacing with this class is done based on column major rules. There are many operations implemented for
	* convenience.
	*
	* @see HVector3
	* @see HVector4
	*/
	class __declspec( align( 16 ) ) HMatrix4x4 
	{
	public:
		/**
		* \fn HMatrix4x4::HMatrix4x4(void)
		* Builds an Identity HMatrix4x4.
		*/
		HMatrix4x4(void);
		~HMatrix4x4(void);

		/**
		* Builds a HMatrix4x4 from another.
		*/
		HMatrix4x4(const HMatrix4x4& other);

		/**
		* Builds a HMatrix4 from 16 floats.
		*/
		HMatrix4x4( hfloat32 r0c0, hfloat32 r0c1, hfloat32 r0c2, hfloat32 r0c3,
						hfloat32 r1c0, hfloat32 r1c1, hfloat32 r1c2, hfloat32 r1c3,
						hfloat32 r2c0, hfloat32 r2c1, hfloat32 r2c2, hfloat32 r2c3,
						hfloat32 r3c0, hfloat32 r3c1, hfloat32 r3c2, hfloat32 r3c3 );

		/**
		* Rights into this HMatrix4x4 from another.
		*
		* @return Returns *this for chaining.
		*/
		HMatrix4x4& operator=(const HMatrix4x4& other );

		/**
		* Transforms a HVector3 through the inner 3x3 of this HMatrix4x4.
		*
		* @return Returns an instance of HVector3 with the transformed data in it.
		*/
		HVector3 operator*( const HVector3& vector );

		/**
		* Transforms a HVector4 through the HMatrix4x4.
		*
		* @return Returns an instance of HVector4 with the transformed data in it.
		*/
		HVector4 operator*( const HVector4& vector );


		__m128& xBase();
		__m128& yBase();
		__m128& zBase();
		__m128& translation();

		/**
		* Multiplies a HMatrix4 by another 
		*/
		HMatrix4x4 operator*( const HMatrix4x4& other );

		HMatrix4x4& transpose();

	private:
		/**
		* data is stored column contiguous
		*/
		__m128 _xbase;
		__m128 _ybase;
		__m128 _zbase;
		__m128 _translation;
	};
}
